package kis.designpattern.observer;

import java.util.ArrayList;

public class WatherData implements Subject {
	private ArrayList observers;
	private int temp;
	private int humidity;
	private int pressure;

	public WatherData()
	{
		observers = new ArrayList();
	}

	public void addOb(ObServer o)
	{
		observers.add(o);
	}

	public void removeOb(ObServer o)
	{
		int i = observers.indexOf(o);
		if (i > 0)
		{
			observers.remove(i);
		}
	}

	public void notifyOb()
	{
		for (int i = 0; i < observers.size(); i++)
		{
			ObServer ob = (ObServer) observers.get(i);
			ob.update(temp, humidity, pressure);
		}
	}
	public void changed()
	{
		notifyOb();
	}
	public void setParam(int temp,int humidity,int perssure)
	{
		this.temp=temp;
		this.humidity=humidity;
		this.pressure=perssure;
		changed();
	}
}
